<?php

use App\Enums\OpenShop\InvestmentPromotion\UserBaseInfoEnum;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateFranchiseeArchivesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('franchisee_archives', function (Blueprint $table) {
            $table->id();
            $table->integer('mainProcessId')->default(0)->comment('开店主流程id');
            $table->string('mobile', 11)->default('')->comment('招商加盟注册手机号' );
            $table->string('remarkMobile1', 11)->default('')->comment('招商加盟备注手机号——1');
            $table->string('remarkMobile2', 11)->default('')->comment('招商加盟备注手机号--2');
            $table->tinyInteger('isSelfManaged')->default(0)->comment('是否亲自经营 - '.self::arrToStr(UserBaseInfoEnum::IS_SELF_MANAGED));
            $table->integer('shopBudget')->default(0)->comment('开店预算');
            $table->tinyInteger('investmentMode')->default(0)->comment('投资方式 - '.self::arrToStr(UserBaseInfoEnum::INVESTMENT_MODE));
            $table->tinyInteger('financeSource')->default(0)->comment('资金来源 - '.self::arrToStr(UserBaseInfoEnum::FINANCE_SOURCE));
            $table->tinyInteger('cateringExperience')->default(0)->comment('是否有餐饮经验');
            $table->tinyInteger('joinChainExperience')->default(0)->comment('是否有加盟连锁经验');
            $table->tinyInteger('employmentExperience')->default(0)->comment('是否有自营经验');
            $table->tinyInteger('workLife')->default(0)->comment('工作年限');
            $table->tinyInteger('educationalBackground')->default(0)->comment('教育背景');
            $table->string('occupationBackground', 52)->default('')->comment('职业背景');
            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '加盟商档案';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('franchisee_archives');
    }

    public static function arrToStr($data, $split = ":"): string
    {
        $str = '';
        foreach ($data as $k => $v){
            $str .= "{$k} {$split} {$v}";
        }
        return $str;
    }
}
